package ru.gerunn.study.collections;

import java.util.ArrayList;

public class Capacity {

	public static void main(String[] args) throws Exception {
		ArrayList<Integer> a = new ArrayList<Integer>();

		info(a);

		for (int i = 0; i < 100; i++) {
			a.add(i);
			info(a);
		}
	}

	static int getCapacity(ArrayList<?> l) throws Exception {
		java.lang.reflect.Field dataField = ArrayList.class.getDeclaredField("elementData");
		dataField.setAccessible(true);
		return ((Object[]) dataField.get(l)).length;
	}

	static void info(ArrayList<?> list) throws Exception {
		System.out.println("size: " + list.size() + ", capacity: " + getCapacity(list));
	}

}
